package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Reference
    PermissionService permissionService;

    /*新增权限*/
    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){
        log.debug("PermissionController permission===== " +permission.toString());
            try{
            permissionService.add(permission);
            return new Result(true, "权限组新增成功");}
            catch(Exception e){
                throw e;
            }

    };
    /*分页查询*/
    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = permissionService.findByPage(queryPageBean);

     return new Result(true,"权限组分页成功",pageResult);
    }
    @RequestMapping("/delById")
    public Result delById(Integer id){
        permissionService.delById(id);

        return new Result(true,"权限组删除成功");
    }

    /*编辑*/
    @RequestMapping("findById")
    public Result findById(Integer id){
      Permission  permission = permissionService.findById(id);
      log.debug("findById=============permission"+permission);
        return new Result(true,"编辑回显成功",permission);

    }
    /*编辑改*/
    @RequestMapping("/edit")
    public Result edit(@RequestBody Permission permission){
         permissionService.edit(permission);
         return new Result(true,"编辑修改成功");
    }

}
